package com.example;

/**
 * @Author loubobooo
 * @Description #9. 回文数
 * @Date 2019/9/5
 */
public class PalindromeNumber {

    /**
     * @return
     * @Author loubobooo
     * @Description 判断一个整数是否是回文数。回文数是指正序（从左向右）和倒序（从右向左）读都是一样的整数。
     * @Date 2019/9/5 16:37
     * @Param
     **/
    public boolean isPalindrome(int x) {
        if (x < 0 || x > Integer.MAX_VALUE) {
            return false;
        }
        if (x >= 0 && x < 10) {
            return true;
        }
        int number = 0;
        int compareNumber = x;
        while (x % 10 != 0 || x / 10 != 0) {
            int a = x % 10;
            number = number * 10 + a;
            x = x / 10;
        }
        return number == compareNumber;
    }

    public static void main(String[] args) {
        PalindromeNumber palindromeNumber = new PalindromeNumber();
        boolean palindrome = palindromeNumber.isPalindrome(121);
        System.out.println(palindrome);
    }
}
